<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div id="ele">
        <span>
          <a></a>
        </span>
        <span>
          <a></a>
          <a></a>
        </span>
      </div>
    <script>
        const domTree=document.querySelector('#ele');
        console.log('domTree',domTree);
        function dom2Json(domTree) {
            let obj = {};
            obj.tag = domTree.tagName;
            obj.children = [];
            console.log('domTree.children',domTree.children);
            // console.log('domTree.childNodes',domTree.childNodes);
            Array.from(domTree.children).forEach((child) => obj.children.push(dom2Json(child)));

            return obj;
        }
        const res=dom2Json(domTree);
        console.log(res);
    </script>
</body>

</html>